package cn.gogetter.clusterer;

import java.io.File;

import weka.clusterers.Cobweb;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.converters.ArffLoader;
// 增量训练Cobweb算法
public class IncrementalClusterer {
	public static void main(String[] args){
		// 加载数据
		Instances structure = null;
		String path = new File("").getAbsolutePath()+"\\data\\";
		ArffLoader loader = new ArffLoader();
		try {
			loader.setFile(new File(path + "contact-lenses.arff"));
			structure = loader.getStructure();
			// 训练Cobweb
			Cobweb cw = new Cobweb();
			cw.buildClusterer(structure);
			Instance current;
			while((current = loader.getNextInstance(structure)) != null){
				cw.updateClusterer(current);
			}
			cw.updateFinished();
			// 输出生成模型
			System.out.println(cw);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
